#include "./system.h"
#include <QNetworkInterface>

namespace utils {

static std::string macAddress;

const std::string& get_mac_address() {
    if (!macAddress.empty()) {
        return macAddress;
    }

    auto ins = QNetworkInterface::allInterfaces();
    for (auto in : ins) {
        if (in.type() != QNetworkInterface::Ethernet) {
            continue;
        }
        if (in.flags() & QNetworkInterface::IsUp) {
            macAddress = in.hardwareAddress().toStdString();
            break;
        }
    }
    return macAddress;
}

}
